package com.infore.exchange.main.service.impl;


import com.infore.common.model.dto.exchange.JobTaskInfoQuartz;
import com.infore.common.utils.UUIDGenerator;
import com.infore.exchange.main.service.QuartzTaskService;
import com.infore.exchange.main.service.TJobTaskInfoService;
import com.infore.exchange.main.service.TTaskInfoService;
import com.infore.exchange.main.service.TTransformInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;


/**
 * 任务调度实现
 *
 */
@Component("quartzTask")
@Slf4j
public class QuartzTaskServiceImpl implements QuartzTaskService {

    @Autowired
    private TTransformInfoService TTransformInfoService;

    @Autowired
    private TJobTaskInfoService TJobTaskInfoService;

    @Autowired
    private TTaskInfoService taskInfoService;



    /**
     * 数据同步至关系型数据库
     * @param jobId
     */
    @Override
    public void rdbmsDataExchang(String jobId) {

        String schedulId=UUIDGenerator.generator();
        List<JobTaskInfoQuartz> tasks = TJobTaskInfoService.queryJobTaskInfoQuartzByJobId(jobId, 1,1,0);
        for (JobTaskInfoQuartz tk:tasks) {
            taskInfoService.updateTaskRunningStateById(tk.getTaskId(),1);
            if("tableToTable".equalsIgnoreCase(tk.getTaskType())){
                log.info("关系型数据同步\tjobId="+jobId);
                TTransformInfoService.rdbmsDataExchang(schedulId, tk);
            }else if("httpToTable".equalsIgnoreCase(tk.getTaskType())){
                log.info("接口数据同步到表\tjobId="+jobId);
                TTransformInfoService.httpDataExchang(schedulId, tk);
            }
            log.info("已开启同步线程池\tjobId="+jobId);
        }
    }



}
